﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Media;

namespace Base.ModuleBase
{
    public static class ImageBtn
    {
        private static ControlTemplate _imageBtnTemplate;
        private static ControlTemplate _imageRadioBtnTemplate;

        public static bool GetIsImageBtn(DependencyObject obj)
        {
            return (bool)obj.GetValue(IsImageBtnProperty);
        }

        public static void SetIsImageBtn(DependencyObject obj, bool value)
        {
            obj.SetValue(IsImageBtnProperty, value);
        }

        // Using a DependencyProperty as the backing store for IsImageBtn.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty IsImageBtnProperty =
            DependencyProperty.RegisterAttached("IsImageBtn", typeof(bool), typeof(ImageBtn), new PropertyMetadata(false,OnIsImageChanged));

        private static void OnIsImageChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var btn = d as ButtonBase;
            if (btn == null) return;
            if (_imageBtnTemplate == null)
            {
                ResourceDictionary rd=new ResourceDictionary();
                rd.Source=new Uri("pack://application:,,,/Base.ModuleBase;component/Infrastructures/BtnStylesDic.xaml", UriKind.RelativeOrAbsolute);
                _imageBtnTemplate=rd["_ImageBtnTemplate"] as ControlTemplate;
                _imageRadioBtnTemplate=rd["_RadioImageBtnTemplate"] as ControlTemplate;
            }
            if (btn is Button)
                btn.Template = _imageBtnTemplate;
            if (btn is ToggleButton)
                btn.Template = _imageRadioBtnTemplate;
        }


        public static ImageSource GetImage(DependencyObject obj)
        {
            return (ImageSource)obj.GetValue(ImageProperty);
        }

        public static void SetImage(DependencyObject obj, ImageSource value)
        {
            obj.SetValue(ImageProperty, value);
        }

        // Using a DependencyProperty as the backing store for Image.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty ImageProperty =
            DependencyProperty.RegisterAttached("Image", typeof(ImageSource), typeof(ImageBtn), new PropertyMetadata(null,OnChange));

        private static void OnChange(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            d.SetValue(e.Property,e.NewValue);
        }


        public static ImageSource GetHover(DependencyObject obj)
        {
            return (ImageSource)obj.GetValue(HoverProperty);
        }

        public static void SetHover(DependencyObject obj, ImageSource value)
        {
            obj.SetValue(HoverProperty, value);
        }

        // Using a DependencyProperty as the backing store for Hover.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty HoverProperty =
            DependencyProperty.RegisterAttached("Hover", typeof(ImageSource), typeof(ImageBtn), new PropertyMetadata(null,OnChange));



        public static ImageSource GetPressed(DependencyObject obj)
        {
            return (ImageSource)obj.GetValue(PressedProperty);
        }

        public static void SetPressed(DependencyObject obj, ImageSource value)
        {
            obj.SetValue(PressedProperty, value);
        }

        // Using a DependencyProperty as the backing store for Pressed.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty PressedProperty =
            DependencyProperty.RegisterAttached("Pressed", typeof(ImageSource), typeof(ImageBtn), new PropertyMetadata(null,OnChange));




        public static ImageSource GetDisabled(DependencyObject obj)
        {
            return (ImageSource)obj.GetValue(DisabledProperty);
        }

        public static void SetDisabled(DependencyObject obj, ImageSource value)
        {
            obj.SetValue(DisabledProperty, value);
        }

        // Using a DependencyProperty as the backing store for Disabled.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty DisabledProperty =
            DependencyProperty.RegisterAttached("Disabled", typeof(ImageSource), typeof(ImageBtn), new PropertyMetadata(null,OnChange));



        public static string GetTooltip(DependencyObject obj)
        {
            return (string)obj.GetValue(TooltipProperty);
        }

        public static void SetTooltip(DependencyObject obj, string value)
        {
            obj.SetValue(TooltipProperty, value);
        }

        // Using a DependencyProperty as the backing store for Tooltip.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty TooltipProperty =
            DependencyProperty.RegisterAttached("Tooltip", typeof(string), typeof(ImageBtn), new PropertyMetadata(null,OnChange));


    }
}
